#include <stdio.h>
#include <stdlib.h>

typedef struct DATA
{
	int isTry;
	int isError;
} Data;

int error(Data data,int m,int c,int k,int n)
{
	if(m == 0 || m == n || m == c)
		return 0;
	if(m != c)
	{
		data.isError = 1;
		return 1;
	}
	return 0;
}

int doTry(Data ***path,int m,int c,int b,int k,int n,int **stack,int *all)
{
	path[m][c][b].isTry ++;
	if(m == 0 && c == 0 && b == 0)
		return 1;
	int i,j;
	if(b == 1)
	{
		for(i = 1;i <= k;i++)
			for(j = 0;j <= i;j++)
				if(m-j >= 0 && c-(i-j) >= 0 && error(path[m-j][c-(i-j)][0],m,c,k,n) != 1 && path[m-j][c-(i-j)][0].isTry == 0)
					if(doTry(path,m-j,c-(i-j),0,k,n,stack,all))
					{
						stack[*all][0] = m-j;
						stack[*all][1] = c-(i-j);
						stack[*all][2] = 0;
						(*all)++;
						return 1;
					}
	}
	else
	{
		for(i = 1;i <= k;i++)
			for(j = 0;j <= i;j++)
				if(m+j<=n && c+(i-j)<=n && error(path[m+j][c+(i-j)][1],m,c,k,n) != 1 && path[m+j][c+(i-j)][1].isTry == 0)
					if(doTry(path,m+j,c+(i-j),1,k,n,stack,all))
					{
						stack[*all][0] = m+j;
						stack[*all][1] = c+(i-j);
						stack[*all][2] = 1;
						(*all)++;
						return 1;
					}		
	}
	return 0;
}

int main(int argc,char *argv[])
{
	int i,j,n,k;
	FILE *fp,*ft;
	fp=fopen(argv[1],"r");
	ft=fopen(argv[2],"w");
	fscanf(fp,"%d %d",&n,&k);
	Data *** path = malloc((n+1)*sizeof(Data **));
	int ** stack = malloc((n+1)*(n+1)*2*sizeof(int *));
	int all = 0;
	for(i = 0;i < (n+1)*(n+1)*2;i++)
		stack[i]= malloc(3*sizeof(int));
	for(i = 0;i < n+1;i++)
	{
		path[i] = malloc((n+1)*sizeof(Data *));
		for(j = 0;j < n+1;j++)
			path[i][j] = malloc(2*sizeof(Data));	
	}
	if(doTry(path,n,n,1,k,n,stack,&all))
	{
		stack[all][0]=n;
		stack[all][1]=n;
		stack[all][2]=1;
		for(i = all;i>=0;i--)
			fprintf(ft,"(%d,%d,%d)\n",stack[i][0],stack[i][1],stack[i][2]);
	}
	else
		fprintf(ft,"no solution\n");
	return 0;
 }
